Skip to content

Deprecate stellar contract optimize in favor of stellar contract build --optimize.#2241

Merged
fnando merged 4 commits into
mainfrom
build-optimize
Oct 7, 2025
Merged

Deprecate stellar contract optimize in favor of stellar contract build --optimize.#2241
fnando merged 4 commits into
mainfrom
build-optimize

Conversation

@fnando
Copy link
Copy Markdown
Member

@fnando fnando commented Oct 7, 2025

What

$ stellar contract build --optimize
ℹ️ CARGO_BUILD_RUSTFLAGS=--remap-path-prefix=/Users/fnando/.cargo/registry/src= cargo rustc --manifest-path=contracts/foo/Cargo.toml --crate-type=cdylib --target=wasm32v1-none --release
    Finished `release` profile [optimized] target(s) in 0.04s
ℹ️ Build Summary:
   Wasm File: target/wasm32v1-none/release/foo.wasm (537 bytes (original size was 574 bytes))
   Wasm Hash: 9276bc278792b46e89b299bb55beffd6ca2fa2d17d723abe1ec615e6d5752485
   Wasm Size: 537 bytes optimized (original size was 574 bytes)
   Exported Functions: 2 found
     • _
     • hello
✅ Build Complete

$ stellar contract build
ℹ️ CARGO_BUILD_RUSTFLAGS=--remap-path-prefix=/Users/fnando/.cargo/registry/src= cargo rustc --manifest-path=contracts/foo/Cargo.toml --crate-type=cdylib --target=wasm32v1-none --release
    Finished `release` profile [optimized] target(s) in 0.05s
ℹ️ Build Summary:
   Wasm File: target/wasm32v1-none/release/foo.wasm (574 bytes)
   Wasm Hash: b39694f92f640414ccf28326ecf1d3b1b48981167eb00fc00739f71dac344013
   Wasm Size: 574 bytes
   Exported Functions: 2 found
     • _
     • hello
✅ Build Complete

Why

Supersedes #2045.

Known limitations

N/A

@fnando fnando requested a review from a team as a code owner October 7, 2025 22:12
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Oct 7, 2025
@fnando fnando self-assigned this Oct 7, 2025
@fnando fnando added enhancement New feature or request cli Related to Soroban CLI labels Oct 7, 2025
@fnando fnando moved this from Backlog (Not Ready) to Needs Review in DevX Oct 7, 2025
@Shaptic
Copy link
Copy Markdown
Contributor

Shaptic commented Oct 7, 2025

Is there any harm to this being the default behavior and dropped the need for a flag entirely? As in, why wouldn't we always just include an optimized WASM as part of the build process?

Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but suggestion inline about the file name that gets written, I think we can omit the .optimized if we are deprecating.

Comment thread cmd/soroban-cli/src/commands/contract/mod.rs Outdated
Comment thread cmd/soroban-cli/src/commands/contract/build.rs Outdated
@fnando
Copy link
Copy Markdown
Member Author

fnando commented Oct 7, 2025

I'm not opposed to that, especially because the additional-libs feature is enabled by default.

wdyt, @leighmcculloch?

@leighmcculloch
Copy link
Copy Markdown
Member

leighmcculloch commented Oct 7, 2025

Is there any harm to this being the default behavior and dropped the need for a flag entirely? As in, why wouldn't we always just include an optimized WASM as part of the build process?

I think we need to be really confident about wasm-opt and what it does to files if it is the default behaviour on. So maybe lets open an issue about that and explore that separately to this issue.

@Shaptic
Copy link
Copy Markdown
Contributor

Shaptic commented Oct 7, 2025

I think we need to be really confident about wasm-opt and what it does to files if it is the default behaviour on

To be clear, I think we should output both, not just the one optimized variant always.

@leighmcculloch
Copy link
Copy Markdown
Member

I think we should output both

Why? It creates an experience that's not the same as how just using cargo build and the rust compiler works, and in general we've tried to make this as much as possible the "standard rust experience" in as many subtle ways as possible. So I think if we keep the separate file we should have a reason we're continuing to do that.

@fnando fnando merged commit 4cdb254 into main Oct 7, 2025
29 checks passed
@fnando fnando deleted the build-optimize branch October 7, 2025 23:35
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in DevX Oct 7, 2025
@Shaptic
Copy link
Copy Markdown
Contributor

Shaptic commented Oct 7, 2025

Why?

@leighmcculloch eh, just a convenience thing I guess. I would, as a developer, like the optimized version available (for visibility, if anything: I bet a decent number of devs don't even know we have an optimizer) without having to do extra steps so that I can deploy that one to mainnet when I'm ready. I get that it deviates from Rustisms, but it is better devx imo.

Edit: I didn't realize that we may not want to recommend the optimized one by default, though, which changes the equation a bit from our perspective by making it explicitly opt-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to Soroban CLI enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants